<%@ page import="com.resataurant.Entity.Dish" %>
<%@ page import="java.util.List" %>
<%@ page import="com.resataurant.Service.AdminService" %>
<%@ page import="com.resataurant.Service.Impl.AdminServiceImpl" %>
<%@ page import="com.resataurant.Entity.User" %><%--
  Created by IntelliJ IDEA.
  User: 86138
  Date: 2024/5/24
  Time: 上午10:18
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>餐厅管理系统登录解密</title>
    <!-- 新 Bootstrap 核心 CSS 文件 -->
    <!-- 新 Bootstrap 核心 CSS 文件 -->
    <link href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">

    <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>

    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <%--<link href="back.css" rel="stylesheet" type="text/css" />--%>
</head>
<body>
<div class="container">
    <div class="row clearfix">
        <div class="col-md-12 column">
            <nav class="navbar navbar-default" role="navigation">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button> <a class="navbar-brand" href="#">顾客信息</a>
                </div>
                <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                    <ul class="nav navbar-nav">
                        <form class="navbar-form navbar-left" role="search" method="post" action="${pageContext.request.contextPath}/CusManageServletServlet">
                            <div class="form-group">
                                <input type="text" class="form-control" name="UserName" />
                            </div>
                            <button type="submit" class="btn btn-default">查询</button>
                            <button type="button" class="btn btn-default"><a href="manager.jsp">主页面</a></button>

                        </form>
                    </ul>
                </div>

            </nav>
<%
            String res= (String) request.getAttribute("res");
            String result=res;
            request.getSession().removeAttribute("res");
            AdminService adminService = new AdminServiceImpl();
            List<User> userlist=null;
            if(result != null){
                userlist = (List<User>) request.getSession().getAttribute("list");
                if(userlist == null){
                    // Handle the case where "res" is not null but there is no "list" in the session
                    // This could involve setting "list" to a new list, logging an error, etc.
                    // For this example, we'll just create a new list.
                    userlist = adminService.searchUser((String) request.getAttribute("UserName"));
                }
            } else {
                userlist = adminService.searchUser();
            }
            request.getSession().removeAttribute("list");
            request.getSession().removeAttribute("res");

%>
            <table class="table">
                <thead>
                <tr>
                    <th>
                        顾客ID
                    </th>
                    <th>
                        顾客名
                    </th>
                    <th>
                        下单次数
                    </th>
                    <th>
                        上次光顾时间
                    </th>
                    <th>
                        查看详情
                    </th>
                </tr>
                </thead>
                <tbody>

                <%
                    if(userlist!=null) {
                        for (User user : userlist ){
                            user=adminService.userDetail(user);
                            out.write(" <tr>");
                            out.write("<td>" + user.getId()+ "</td>");
                            out.write("<td>" + user.getUsername()+ "</td>");
                            out.write("<td>" + user.getTimes()+ "</td>");
                            out.write("<td>" + user.getLastTime() + "</td>");
                            out.write("<td><a href='ReportFormServlet?UserId="+user.getId()+"&method=userData&UserName="+user.getUsername()+"'>查看详情</a></td>");
                            out.write(" </tr>");
                        }
                    }
                %>

                </tbody>
            </table>
        </div>
    </div>
</div>
</body>
</html>
